$("#sell-all").click(function() {   
  for (var i = 0; i < 10; i++) {
    var elem = $("#comment-"+i);
    if (elem.obj() != null) {elem.obj().checked = this.checked;}
  }
  return 0;
});
$("#panel-form_btn").click(function(){$("#opin-form").hide();})
$("#comment-edit").click(function() {
  var id = 0;
  for (var i = 0; i < 10; i++) {
    var elem = $("#comment-"+i);
    if (elem.obj() != null && elem.obj().checked) {id = elem.value(); break;}
  }
  if (id != 0) {$.post("index.php", "no_sef=1&0=ajax&1=comments&2=edit&id="+id, commentEdit);}
});
$("#comment-delete").click(function() {
  var ids = "";
  for (var i = 0; i < 10; i++) {
    var elem = $("#comment-"+i);
    if (elem.obj() != null && elem.obj().checked) {ids += (ids != "")?(","+elem.value()):(elem.value());}
  }
  if (ids != "") {$.post("index.php", "no_sef=1&0=ajax&1=comments&2=delete&ids="+ids, commentRequest);}
});
$("#comment-on").click(function() {
  var ids = "";
  for (var i = 0; i < 10; i++) {
    var elem = $("#comment-"+i);
    if (elem.obj() != null && elem.obj().checked) {ids += (ids != "")?(","+elem.value()):(elem.value());}
  }
  if (ids != "") {$.post("index.php", "no_sef=1&0=ajax&1=comments&2=on&ids="+ids, commentRequest);}
});
$("#comment-off").click(function() {
  var ids = "";
  for (var i = 0; i < 10; i++) {
    var elem = $("#comment-"+i);
    if (elem.obj() != null && elem.obj().checked) {ids += (ids != "")?(","+elem.value()):(elem.value());}
  }
  if (ids != "") {$.post("index.php", "no_sef=1&0=ajax&1=comments&2=off&ids="+ids, commentRequest);}
});


function commentEdit(request) {
  if (!request.rez) {return 0;}
  $("#user-name").value(request.user_name);
  $("#opin-nstars").value(request.nstars);
  $("#opin-worth").value(request.worth);
  $("#opin-limitations").value(request.limitations);
  $("#opin-comment").value(request.comment);
  $("#power-id").value(request.power_id);
  $("#opin-id").value(request.opin_id);
  $("#opin-form").show();
  return 0;
}
function commentRequest(request) {
  if (!request.rez) {return 0;}
  window.location.href = window.location.pathname;
  return 0;
}
